/*----------------------------------------------------------
* FILE: LinkToFileDecorator.java
* LOGICAL NAME: LinkToFileDecorator
* PRODUCT: bila-framework
*----------------------------------------------------------
* MODIFICATIONS
* DATE Oct 10, 2011
* AUTHOR wjuarez
*----------------------------------------------------------
*/

package bila.framework.displaytag.decorator;

import javax.servlet.jsp.PageContext;

import org.displaytag.decorator.DisplaytagColumnDecorator;
import org.displaytag.exception.DecoratorException;
import org.displaytag.properties.MediaTypeEnum;

/**
 * @author WJuarez
 * <b>Created by </b>wjuarez
 * <b>for</b> bila-framework
 * <b>package</b> bila.framework.displaytag.decorator
 * <b>on</b> Oct 10, 2011 9:42:01 PM
 * <b>Purpose</b> 
 * <p>
 *		Decorator para generar link para acceso a documentos
 * </p>
 */
public class LinkToFileDecorator implements DisplaytagColumnDecorator {

	/*
	 * (non-Javadoc)
	 * @see org.displaytag.decorator.DisplaytagColumnDecorator#decorate(java.lang.Object, javax.servlet.jsp.PageContext, org.displaytag.properties.MediaTypeEnum)
	 */
	public Object decorate(Object columnValue, PageContext pageContext, MediaTypeEnum media) throws DecoratorException {
		if(columnValue !=  null){
			String column = (String) columnValue;
			column = column.replace("\\", "/");			
			String ctx = pageContext.getServletContext().getServletContextName();
			String image = "<img alt=\"PDF\" src=\"" + ctx + "/images/theme/pdf.gif\"/>";
			column = "<a href=\"javascript:openWindow('" + column + "')\">" + image + "</a>";
			return column;
		}
		return null;
	}

}
